package com.ztz.mynewdemo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.widget.Toast;

/**
 * Created by wqewqe on 2017/12/15.
 */

public class MyDbHelper extends SQLiteOpenHelper {
    public static final String CREATE_USERINFO="create table UserInfo(" +
            "id integer primary key autoincrement," +
            "userName text," +
            "password text," +
            "content text)";
    private Context mContext;
    public MyDbHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
        mContext=context;
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_USERINFO);
        Toast.makeText(mContext, "数据库创建成功", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("drop table if exists UserInfo");
        onCreate(db);
    }
}
